﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Imports System.IO
Imports System.Runtime.InteropServices

Public Class clsImages

    Private Images As New ImageList
    Private ds As New DataSet("images")
    Private tb_images As DataTable

    Private Structure SHFILEINFO
        Public hIcon As IntPtr            ' : icon
        Public iIcon As Integer           ' : icondex
        Public dwAttributes As Integer    ' : SFGAO_ flags
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> Public szDisplayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> Public szTypeName As String
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr
    Private Const SHGFI_ICON = &H100
    Private Const SHGFI_SMALLICON = &H1
    Private Const SHGFI_LARGEICON = &H0    ' Large icon
    Private Const MAX_PATH = 260

    Public ReadOnly Property bmpImageList()
        Get
            Return Images
        End Get
    End Property

    Public Sub New()
        ds.ReadXml(Application.StartupPath & "\resources\xml\icons.xml")
        tb_images = ds.Tables("image")
        For Each bmp As DataRow In tb_images.Rows
            Images.Images.Add(bmp("key"), Bitmap.FromFile(Application.StartupPath & "\resources\images\" & bmp("filename")))
        Next
    End Sub

    Public Function KeyExists(ByVal Key As String) As Boolean
        For Each bmp As DataRow In tb_images.Rows
            If bmp("key") = Key Then
                Return True
            End If
        Next
        Return False
    End Function

    Public Function bmpImage(ByVal Key As String) As Image
        For Each bmp As DataRow In tb_images.Rows
            If bmp("key") = Key Then
                Return Image.FromFile(Application.StartupPath & "\resources\images\" & bmp("filename"))
            End If
        Next
        Return Nothing
    End Function

    Public Function bmpImageFromFile(ByVal Path As String) As Image
        bmpImageFromFile = Nothing
        Return Image.FromFile(Path)
    End Function

    Public Function IndexOfKey(ByVal Key As String) As Long
        For i = 0 To Me.Images.Images.Keys.Count - 1
            If Me.Images.Images.Keys(i) = Key Then
                Return i
            End If
        Next
        Return Nothing
    End Function

End Class
